package com.atguigu.mySmartCampus.controller;

import com.atguigu.mySmartCampus.Service.GradeService;
import com.atguigu.mySmartCampus.entity.Grade;
import com.atguigu.mySmartCampus.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags="年级控制")
//+
@RequestMapping("/sms/gradeController")
public class GradeController{

    @Autowired
    GradeService gradeService;

    @ApiOperation("删除")
    @DeleteMapping("/deleteGrade")
    //..public Result deleteGrade(@Apiparam("要删除的n个id")  List<Integer> ids){
        public Result deleteGrade(@ApiParam("要删除的n个id") @RequestBody List<Integer> ids){
    //..gradeService.removeIds(ids);
        gradeService.removeByIds(ids);
        return Result.ok();
    }

    @GetMapping("/getGrades")
    public Result getGrade(){
        List<Grade> list = gradeService.getGrade();
        return Result.ok(list);
    }

    //过于简单  难以置信
    @PostMapping("/saveOrUpdateGrade")
    public Result saveOrUpdateGrade(@RequestBody Grade grade){
        boolean b = gradeService.saveOrUpdate(grade);
        return Result.ok(b);
    }
    //+
    //..@GetMapping("/getGradeByOperator/{pageSize}/{pageNum}")
    @GetMapping("/getGrades/{pageNum}/{pageSize}")
    //..public Result getGradeByOperator(Page pageParam,String gradeName){
        public Result getGradeByOperator(@PathVariable Integer pageNum,
        @PathVariable Integer pageSize,
        String gradeName){
            //+
            Page<Grade> page = new Page(pageNum,pageSize);

        //..gradeService.getGradeByOperator(page,gradeName);
        IPage<Grade> ipage =gradeService.getGradeByOperator(page,gradeName);
        return Result.ok(ipage);
    }
}